Skip to content

fix: Offer to reset a local database that a crash left unable to start. - #16

Merged
vlidholt merged 2 commits into
mainfrom
fix/damaged-local-database
Dec 3, 2026
Merged

vlidholt merged 2 commits into
mainfrom
fix/damaged-local-database

Conversation

@vlidholt

@vlidholt vlidholt commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

A new project on Windows stopped being able to start its server. Postgres refused postgresql.conf on every start (syntax error … line 1, near token ""), and Try Again failed the same way each time. That message is what Postgres prints for a configuration file that starts with NUL bytes. The Serverpod CLI creates the cluster with initdb --no-sync and rewrites the file unflushed, so a computer that crashes or loses power soon after a project's first start can come back with it zero-filled, and the CLI never recreates the cluster.

Reported upstream as serverpod/serverpod#6081; serverpod/serverpod#5996 is an earlier case of the same message. This PR is App Studio's way out for the user in the meantime.

What changes

  • Detection. After any failed start or runner exit, findDamagedDatabases reads the cluster's text files (PG_VERSION, postgresql.conf, pg_hba.conf, pg_ident.conf) under <server>/.serverpod/<mode>/pgdata and reports a data directory when one of them holds a NUL byte. It reads the disk, not the log, so it does not depend on the CLI's wording.
  • Status and log. The toolbar reads "Database error" instead of "Stopped", and the server log gets a plain explanation under the runner's own error.
  • Reset Database takes Try Again's place. It asks first, since the data is lost. On confirm it deletes what EmbeddedPostgres.reset() deletes (the data directory, run beside it, and the pid, log, state and password files), then starts the server, which creates the database again and applies the migrations. The damage is looked for again at that moment, so an intact database is never deleted.
  • Toolbar. A stopped status message is capped at what the actions' icon form leaves, so a longer one ellipsizes instead of overflowing.
  • Docs. A new section in AGENTS.md, and specs/embedded_postgres_zeroed_conf_report.md with the analysis and the upstream report.

Verification

  • flutter analyze is clean, and flutter test -x process -j 1 passes on the Windows dev laptop (920 passed, 16 skipped).
  • New tests: file-level detection and reset (test/runner/runner_postgres_test.dart), the controller's side (test/process/database_reset_test.dart, not tagged process since every start in it fails before a runner exists), and the toolbar and dialog (test/ui/studio_toolbar_test.dart). Widgetbook has a "Database damaged" window and the dialog.
  • Looked at the toolbar and the dialog running in Widgetbook on Windows.

Not verified

  • The process-tagged controller tests were not run locally; CI runs them on macOS.
  • The reset was tested against files in a scratch project, not against a real zero-filled cluster with a real runner.
  • Only the zero-filled postgresql.conf was reproduced, by having the bundled Postgres parse a test file. That the affected machine's file is zero-filled is inferred from its error message; the other three files are included by the same reasoning.
  • A project whose database.dataPath points outside .serverpod/<mode> is not covered.

🤖 Generated with Claude Code

vlidholt and others added 2 commits December 3, 2026 14:58
A new project on Windows stopped being able to start its server: Postgres
refused postgresql.conf on every start ("syntax error ... line 1, near token
"""), and Try Again failed the same way each time. That message is what
Postgres prints for a configuration file that starts with NUL bytes. The
Serverpod CLI creates the cluster with initdb --no-sync and rewrites the
file unflushed, so a computer that crashes or loses power soon after a
project's first start can come back with it zero-filled, and the CLI never
recreates the cluster.

- After any failed start or runner exit, findDamagedDatabases reads the
  cluster's text files under .serverpod/<mode>/pgdata and reports a data
  directory when one of them holds a NUL byte.
- The status then reads "Database error", the log explains what happened,
  and Reset Database takes Try Again's place. It asks first, deletes what
  EmbeddedPostgres.reset() deletes, and starts the server, which creates the
  database again and applies the migrations. The damage is looked for again
  at that moment, so an intact database is never deleted.
- A stopped status message is capped at what the actions' icon form leaves,
  so a longer one ellipsizes instead of overflowing the toolbar.
- specs/embedded_postgres_zeroed_conf_report.md has the analysis and the
  report for Serverpod.

Only the zero-filled postgresql.conf was reproduced, with the bundled
Postgres parsing a test file; that the affected machine's file is zero-filled
is inferred from its error message. The reset was tested against files in a
scratch project, not against a real cluster and runner. The process-tagged
controller tests were not run on the Windows dev laptop.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vlidholt
vlidholt merged commit 4f10342 into main Dec 3, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant